#pragma once
#include <string>
#include <iostream>
#include <memory>
#include<functional>
#include "Addr.hpp"
class Reactor;
class Connection;
// 我们需要给每一个fd都分配一个buffer空间,所以使用connection类来管理
// 我们使用string来充当buffer空间
using handler_t =std::function<std::string (std::string& inbuffer)>;
class Connection
{
public:
    Connection()
    {
    }
    virtual void Recver() = 0;
    virtual void Sender() = 0;
    virtual void Excepter() = 0;
    void SetEvents(uint32_t events)
    {
        _events = events;
    }
    void SetFd(int fd)
    {
        _sockfd = fd;
    }
    int GetFd()
    {
        return _sockfd;
    }
    uint32_t GetEvents()
    {
        return _events;
    }
    void SetOwner(Reactor *owner)
    {
        _owner = owner;
    }
    void RegisterHandler(handler_t handler)
    {
        _handler=handler;
    }
    Reactor *GetOwner()
    {
        return _owner;
    }
    ~Connection()
    {
    }

private:
    int _sockfd;
    Reactor *_owner;  // 回指指针
    uint32_t _events; // 关心的事件
public:
    handler_t _handler;
};